/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Ultility;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

/**
 *
 * @author Yihao Li
 */
public class readTextlines {

    public int count = 0;
    String s = "";
    String ss = "";

    public readTextlines(String filePath) {
        File f = new File(filePath);
        try {
            BufferedReader br = new BufferedReader(new FileReader(f));
            while (br.ready()) {
                s = br.readLine();
                count++;
               
            } br.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public int getCount() {
        return count;
    }

    public String[] getData(String filePath) {
        String[] d = new String[count];
        File f = new File(filePath);
        try {
            BufferedReader br = new BufferedReader(new FileReader(f));
            for (int j = 0; j < d.length; j++) {
                s = "";
                s = br.readLine();
                ss = "";
                for (int i = 0; i < s.length(); i++) {
                    if (s.charAt(i) == ' ') {
                        break;
                    }
                    ss = ss + s.charAt(i);
                }
                d[j] = ss;
            }
            
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return d;
    }
}
